/*
 * Copyright 2013 Palantir Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.palantir.typescript.text;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.information.IInformationProviderExtension;
import org.eclipse.jface.text.information.InformationPresenter;

/**
 * Provides the information for an {@link InformationPresenter}.
 *
 * @author tyleradams
 */
public final class InformationProvider implements IInformationProvider, IInformationProviderExtension {

    private final TypeScriptEditor editor;

    public InformationProvider(TypeScriptEditor editor) {
        checkNotNull(editor);

        this.editor = editor;
    }

    @Override
    public String getInformation(ITextViewer textViewer, IRegion subject) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object getInformation2(ITextViewer textViewer, IRegion subject) {
        return this.editor.getLanguageService().getNavigationBarItems();
    }

    @Override
    public IRegion getSubject(ITextViewer textViewer, int offset) {
        checkArgument(offset >= 0);

        return new Region(offset, 0);
    }
}
